package com.equipmentRent.web.controller.system;


import com.equipmentRent.common.annotation.Log;
import com.equipmentRent.common.core.controller.BaseController;
import com.equipmentRent.common.core.domain.AjaxResult;
import com.equipmentRent.common.core.page.TableDataInfo;
import com.equipmentRent.common.enums.BusinessType;
import com.equipmentRent.common.utils.poi.ExcelUtil;
import com.equipmentRent.system.domain.BannerConfig;
import com.equipmentRent.system.service.IBannerConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * banner配置Controller
 * 
 * @author biz
 * @date 2025-03-23
 */
@Controller
@RequestMapping("/system/banner")
public class BannerConfigController extends BaseController
{
    private String prefix = "system/banner";

    @Autowired
    private IBannerConfigService bannerConfigService;

    @RequiresPermissions("system:banner:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/banner";
    }

    /**
     * 查询banner配置列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BannerConfig bannerConfig)
    {
        startPage();
        List<BannerConfig> list = bannerConfigService.selectBannerConfigList(bannerConfig);
        return getDataTable(list);
    }


    @PostMapping("/getBannerList")
    @ResponseBody
    public AjaxResult getBannerList()
    {
        List<BannerConfig> list = bannerConfigService.selectBannerConfigList(new BannerConfig());
        return AjaxResult.success(list);
    }

    /**
     * 导出banner配置列表
     */
    @RequiresPermissions("system:banner:export")
    @Log(title = "banner配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BannerConfig bannerConfig)
    {
        List<BannerConfig> list = bannerConfigService.selectBannerConfigList(bannerConfig);
        ExcelUtil<BannerConfig> util = new ExcelUtil<BannerConfig>(BannerConfig.class);
        return util.exportExcel(list, "banner配置数据");
    }

    /**
     * 新增banner配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存banner配置
     */
    @RequiresPermissions("system:banner:add")
    @Log(title = "banner配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BannerConfig bannerConfig)
    {
        return toAjax(bannerConfigService.insertBannerConfig(bannerConfig));
    }

    /**
     * 修改banner配置
     */
    @RequiresPermissions("system:banner:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BannerConfig bannerConfig = bannerConfigService.selectBannerConfigById(id);
        mmap.put("bannerConfig", bannerConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存banner配置
     */
    @RequiresPermissions("system:banner:edit")
    @Log(title = "banner配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BannerConfig bannerConfig)
    {
        return toAjax(bannerConfigService.updateBannerConfig(bannerConfig));
    }

    /**
     * 删除banner配置
     */
    @RequiresPermissions("system:banner:remove")
    @Log(title = "banner配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bannerConfigService.softDeleteBannerConfigByIds(ids));
    }
}
